#!/bin/bash
if [ -n "$1" ]; then
	prefix="$1"; shift
	ct=1 #start at one
	while [ -n "$1" ]; do
		if [ -f "$1" ]; then
			#dest="`dirname $1`/$prefix"
			dest="${1%/*}/$prefix"
			while [ -f "$dest$ct" ]; do
				let ct=ct+1
			done
			mv -v "$1" "$dest$ct" #the -v switch displays what we did
			let ct=ct+1 #avoid a useless test for the next argument
		else
			echo "$1 isn't a regular file: skipped"
		fi
		shift
	done
else
	echo usage: `basename $0` prefix [file...]
	echo "Renames regular files (relative and absolute paths are supported) with a prefix and a number."
	echo For each file, the number is incremented until the file can be moved without overwriting any other.
fi
